package com.wd.health.model.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.wd.health.R;
import com.wd.health.model.bean.CjbzBean02;

import java.util.List;

/**
 * @ProjectName:shopmall
 * @Package:com.bawei.myhealth.model.adapter
 * @ClassName:CjbzAdapter02
 * @UpdateUser: 裴童童
 * @date: 2020/12/8
 */
public class CjbzAdapter02 extends RecyclerView.Adapter<CjbzAdapter02.ViewHolder>{
    private List<CjbzBean02.ResultBean> result;
    private Context context;

    public CjbzAdapter02(List<CjbzBean02.ResultBean> result, Context context) {
        this.result = result;
        this.context = context;
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        return new ViewHolder(View.inflate(context, R.layout.item_cjbz,null));
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, final int position) {
        holder.tv.setText(result.get(position).getName());
        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String name = result.get(position).getName();
                //一定要刷新适配器 当条目发生改变这是必须的
                getListener.onClick(name,result.get(position).getId());
                notifyDataSetChanged();
            }
        });
    }

    @Override
    public int getItemCount() {
        return result.size();
    }

    class ViewHolder extends RecyclerView.ViewHolder {

        private final TextView tv;

        public ViewHolder(@NonNull View itemView) {
            super(itemView);
            tv = itemView.findViewById(R.id.tv_cjbz_name);
        }
    }

    //接口回调
    public interface GetListener {
        void onClick(String name, int id);
    }

    private GetListener getListener;

    public void setGetListener(GetListener getListener) {
        this.getListener = getListener;
    }
    private  int mPosition;

    public int getmPosition() {
        return mPosition;
    }

    public void setmPosition(int mPosition) {
        this.mPosition = mPosition;
    }
} 
